package com.csw.shuanfa.bitset;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;

/**
 * list 100万次 操作
 * add]1ms
 * size]0ms
 * get]0ms
 * boolean]1ms
 * contains]1ms
 * sort]97ms
 * bitset]2ms
 * retainAll]2068ms   100个 性能差
 * remove 极其影响性能
 */
public class ListMethodTest {
    public static void main(String[] args) throws InterruptedException {
        int num = (int) Math.pow(10, 4);
        List<Integer> list = new ArrayList();
        /**
         * add
         */
        Long startAdd = System.currentTimeMillis();
        for (int i = 0; i < num; i++) {
            list.add(i);
        }
        Long endAdd = System.currentTimeMillis();
        //add]" + (endAdd - startAdd) + "ms");

        /**
         *size
         */
        Long startSize = System.currentTimeMillis();
        for (int i = 0; i < num; i++) {
            list.size();

        }
        Long endSize = System.currentTimeMillis();
        //size]" + (endSize - startSize) + "ms");

        /**
         *get
         */
        Long startGet = System.currentTimeMillis();
        for (int i = 0; i < num; i++) {
            list.get(i);

        }
        Long endGet = System.currentTimeMillis();
        //get]" + (endGet - startGet) + "ms");

        /**
         *boolean
         */
        Long startBoolean = System.currentTimeMillis();
        for (int i = 0; i < num; i++) {
            if (list.get(i) > 0) {

            }

        }
        Long endBoolean = System.currentTimeMillis();
        //boolean]" + (endBoolean - startBoolean) + "ms");

        /**
         *contains
         */
        Long startcontains = System.currentTimeMillis();
        for (int i = 0; i < num; i++) {
            if (list.contains(0)) {

            }

        }
        Long endcontains = System.currentTimeMillis();
        //contains]" + (endcontains - startcontains) + "ms");
        /**
         *sort
         */
        Long startsort = System.currentTimeMillis();
        for (int i = 0; i < num; i++) {
            Collections.sort(list);

        }
        Long endsort = System.currentTimeMillis();
        //sort]" + (endsort - startsort) + "ms");

        /**
         *bitset
         */
        Long startbitset = System.currentTimeMillis();
        BitSet bit = new BitSet(num);
        for (int i = 0; i < num; i++) {
            bit.set(i);

        }
        for (int i = 0; i < num; i++) {
            if (bit.get(i)) {
                // //i);
            }
        }

        Long endbitset = System.currentTimeMillis();
        //bitset]" + (endbitset - startbitset) + "ms");


        /**
         *retainAll
         */
        num = 100;
        Long startretainAll = System.currentTimeMillis();
        for (int i = 0; i < num; i++) {
            if (list.retainAll(list)) {

            }

        }
        Long endretainAll = System.currentTimeMillis();
        //retainAll]" + (endretainAll - startretainAll) + "ms");
        /**
         *remove
         */
//        Long startRemove = System.currentTimeMillis();
//        for (int i = 0; i < num; i++) {
//            list.remove(i);
//
//        }
//        Long endRemove = System.currentTimeMillis();
//        //remove]" + (endRemove - startRemove) + "ms");


    }
}
